package com.terrier.ui.controls
{
    import com.terrier.ui.controls.sliderClasses.WxSliderBase;
    import com.terrier.ui.skins.WxSkinManager;

    import flash.geom.Point;

    /**
     * 垂直滑块
     * @author Jarvis.weng
     */
    public class WxVSlider extends WxSliderBase
    {
        /**
         * 构造函数
         */
        public function WxVSlider()
        {
            super();
        }

        /**
         * @private
         */
        override public function setSkinID(skinID:String):void
        {
            setSkin(WxSkinManager.getVSliderSkin(skinID));
        }

        /**
         * @private
         */
        override protected function updateView():void
        {
            if (!isDrag)
            {
                updateThumbPosition();
            }
        }

        /**
         * @private
         */
        override protected function dragThumb(pt:Point):void
        {
            var minPos:Number = track.x;
            var maxPos:Number = track.x + track.height - thumb.height;
            var posRange:Number = maxPos - minPos;
            var yPos:Number = Math.max(minPos, Math.min(pt.y, maxPos));

            var oldValue:Number = value;
            value = (maxPos - yPos) / posRange * range + minimum;

            if (oldValue != value)
            {
                updateThumbPosition();
            }

            updateToolTip();
        }

        /**
         * @private
         */
        override protected function updateThumbPosition():void
        {
            var minPos:Number = track.x;
            var maxPos:Number = track.x + track.height - thumb.height;
            var posRange:Number = maxPos - minPos;

            thumb.y = minPos + (posRange - percentValue * (posRange));
        }

        /**
         * @private
         */
        override protected function pointToValue(pt:Point):Number
        {
            var minPos:Number = 0;
            var maxPos:Number = track.height - thumb.height;
            var posRange:Number = maxPos - minPos;
            var yPos:Number = pt.y;

            return (maxPos - yPos) / posRange * range + minimum;
        }

        /**
         * @private
         */
        public override function set height(value:Number):void
        {
            track.height = value;
            updateView();
        }

        /**
         * @private
         */
        public override function get height():Number
        {
            return track.height;
        }
    }
}
